// pages/qualityControl/equipmentManage/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winHeight:"",
    allData: [],
    inputValue: "",
    inputFocus: false,
    searchHis: [],
    historyShow: false,
    clearShow: false, // 点叉了吗
  },
  watchInput(event) {
    let juge = this.data.clearShow
    if (!juge) {
      this.setData({
        clearShow: true
      })
    }
    this.data.inputValue = event.detail.value
    console.log('输入的话', event.detail)

  },
  // 事件触发函数
  clear() {

    this.setData({
      inputValue: '',
      clearShow: false,

      // list: [],
      // pageIndex: 1
    })
    this.getAllData()
    console.log('小图标不配绑定事件？')
  },
  getAllData() {
    let self = this
    self
      .axios
      .query(
        "QualityControlEquipment",
        {},
        {keyValue:self.data.inputValue},
        ""
      )
      .then(function (response) {
        let arr= response.data.rows
        arr.forEach(e=>{
          e.calibrationDate = e.calibrationDate.substring(0,e.calibrationDate.length-9)
          e.dueDate = e.dueDate.substring(0,e.dueDate.length-9)
        })
        self.setData({
          allData: arr
        })
      })
      .catch(function (response) {

      });
  },
  addQuality() {
    this.Router.push("addEquipment")
  },
  detail(e) {
    console.log(e.currentTarget.dataset.item)
    wx.navigateTo({
      url: './detailEquipment/index',
      success: function (res) {
        res.eventChannel.emit('toEquipmentdetail', { item: e.currentTarget.dataset.item })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 高度自适应
    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 240;
        console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });
    this.getAllData()

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getAllData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})